// src/router/index.js

import {createRouter, createWebHashHistory} from "vue-router"
const Layout = import(`../layout/index.vue`);

const router = createRouter({ 
  history: createWebHashHistory(),  // hash 模式
  // history: createWebHistory(),  // history 模式
  routes: [
    {
      path: '/',
      name: 'Layout',
      component:Layout,
      meta: {
        title: '首页',
      },
      redirect: '/home',
      children: [
        {
          path: '/home',
          name: 'Home',
          component: () => import(`../views/home/index.vue`),
          meta: {
            header: true,
            footer: true
          }
        },
        {
          path: '/templateDetail',
          name: 'TemplateDetail',
          component: () => import(`../views/templateDetail/index.vue`),
          meta: {
            header: true,
            footer: true
          }
        },
        {
          path: '/editPage',
          name: 'EditPage',
          component: () => import(`../views/editPage/index.vue`),
          meta: {
            header: true,
            footer: false
          }
        }
      ]
    },
    {
      path: '/list',
      name: 'list',
      component: () => import(`../views/list.vue`),
      meta: {
        title: '列表页',
      },
    },
    {
      path: '/*',
      redirect: '/',
    },
  ]
})

// // 全局路由守卫
// router.beforeEach((to, from, next)=>{
//   // console.log(to, from)
//   if (to.meta.title) {
//     document.title = `${to.meta.title}`;
//   }
//   next()
// })

// router.afterEach((to, from)=>{
//   // console.log(to, from)
//   console.log('afterEach')
// })

export default router